import { _decorator, Component, Node, Label, AudioClip } from 'cc';
const { ccclass, property } = _decorator;

import { SSS_Consts } from "../../../../Script/Data/SSS_Consts";
import { bdlMgr } from "../../../../Script/Manager/BundleManager_S";
import SSS_GameEventManager, { SS_GameEventData } from "../../../../Script/Manager/SSS_GameEventManager";
import { SSS_AudioManager } from 'db://assets/Script/Manager/SSS_AudioManager';

@ccclass('LianLianKan_WinPanel')
export default class LianLianKan_WinPanel extends Component {
    public static Instance: LianLianKan_WinPanel;
    @property(Node)
    public Button_menu: Node | null = null;
    @property(Node)
    public Button_next: Node | null = null;
    // @property(Node)
    // public Button_replay: Node | null = null;

    // @property(Label)
    // public Label_time_current: Label | null = null;
    // @property(Label)
    // public Label_step_number_current: Label | null = null;
    // @property(Label)
    // public Label_time_record: Label | null = null;
    // @property(Label)
    // public Label_step_number_record: Label | null = null;

    onLoad() {
        LianLianKan_WinPanel.Instance = this;
    }

    ShowOn() {
        this.node.active = true;
        this.AddListener();
        this.Refresh();

        let audio_root = `audio/Win sound/Win sound 4`;
        bdlMgr.getRes<AudioClip>(SSS_Consts.BundleName.AUDIO, audio_root, AudioClip).then(res => {
            SSS_AudioManager.Instance.playSFX(res, false);
        });
    }

    ShowOff() {
        this.node.active = false;
        this.RemoveListener();
    }
    async Refresh() {

    }
    AddListener() {
        this.Button_menu.on(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_next.on(Node.EventType.TOUCH_END, this.On_Button_next, this);
        // this.Button_replay.on(Node.EventType.TOUCH_END, this.On_Button_replay, this);
    }
    RemoveListener() {
        this.Button_menu.off(Node.EventType.TOUCH_END, this.On_Button_menu, this);
        this.Button_next.off(Node.EventType.TOUCH_END, this.On_Button_next, this);
        // this.Button_replay.off(Node.EventType.TOUCH_END, this.On_Button_replay, this);
    }
    On_Button_menu() {
        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Menu);
        SSS_AudioManager.PlayButtonAudio();
    }
    On_Button_replay() {
        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Replay);
    }
    On_Button_next() {
        // console.log(`On_Button_next`);
        this.ShowOff();
        SSS_GameEventManager.eventTarget.emit(SS_GameEventData.Next_Level);
        SSS_AudioManager.PlayButtonAudio();
    }
}